package com.neusoft.productsys.dao.impl;

import com.neusoft.productsys.common.BaseDAO;
import com.neusoft.productsys.dao.ILoginDAO;
import com.neusoft.productsys.entity.UserInfo;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class LoginDAOImpl extends BaseDAO<UserInfo> implements ILoginDAO {
    @Override
    protected List<UserInfo> resultToList(ResultSet rs) throws SQLException {
        List<UserInfo> list = new ArrayList<>();
        while (rs.next())
        {
            UserInfo u = new UserInfo();
            u.setUname(rs.getString("uname"));
            u.setPwd(rs.getString("pwd"));
            list.add(u);
        }
        return list;
    }

    @Override
    public UserInfo Login(String uname, String pwd) {
        String sql = "select * from t_user where uname=? and pwd=?";
        Object[] objects = {uname,pwd};
        List<UserInfo> list = this.exec_Query(sql,objects,"验证用户是否存在");
        if (list.size()>0)
            return list.get(0);
        else
            return null;
    }
}
